from impala.dbapi import connect

# Impala 配置信息
host = '192.168.66.181'
port = 21050
database = 'ods'


def query_impala(sql_query):
    """

    :param sql_query:
    """
    # 连接到 Impala
    conn = connect(host=host, port=port, database=database)
    cursor = conn.cursor()

    try:
        # 执行查询
        cursor.execute(sql_query)

        # 获取查询结果
        results = cursor.fetchall()
        for row in results:
            print(row)

    except Exception as e:
        print(f"查询失败: {e}")

    finally:
        # 关闭连接
        cursor.close()
        conn.close()


# 调用函数并执行查询
# sql_query = "select * from ods.ods_superex_trade_spot_finance_record limit 100;"
sql_query = "select protocol, count(*) AS currency_count from ods.ods_superex_trade_currency_chain where currency_type = 0 group by protocol"
query_impala(sql_query)



# select prococol, count(*) from ods.ods_superex_trade_currency_chain group by protocol where currency_type = 0